package com.iflytek.yly.jetpackdemo.lifecycle;

import android.app.Activity;

import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.OnLifecycleEvent;

public class MyLocationListener implements LifecycleObserver {

    public MyLocationListener(Activity context,
                              OnLocationChangeListener onLocationChangeListener){

        //初始化操作
        LocationManager.getInstance().initLocationManager();
    }

    /**
     * 当Activity执行onResume()方法时，该方法会被自动调用
     */
    @OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
    private void startGetLocation(){
        LocationManager.getInstance().startGetLocation();
    }

    /**
     * 当Activity执行onPause()方法时，该方法会被自动调用
     */
    @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
    private void stopGetLocation(){
        LocationManager.getInstance().stopGetLocation();
    }


    /**
     * 当地理位置发生变化时，通过该接口通知调用者
     */
    public interface OnLocationChangeListener{
        void onChanged(double latitude, double longitude);
    }

    // 其他一些业务代码
}
